package cn.com.elite;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.Types;
import java.util.List;

import javax.sql.DataSource;

import oracle.jdbc.OracleTypes;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.jdbc.core.CallableStatementCallback;
import org.springframework.jdbc.core.CallableStatementCreator;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;

public class FtpBean {
	private static final Log log=LogFactory.getLog(FtpBean.class);
    private DataSource dataSource;
    private DataSourceTransactionManager tran;
    private PlatformTransactionManager transactionManager;
    
	public PlatformTransactionManager getTransactionManager() {
		return transactionManager;
	}
	public void setTransactionManager(PlatformTransactionManager transactionManager) {
		this.transactionManager = transactionManager;
	}
	public DataSource getDataSource() {
		return dataSource;
	}
	public void setDataSource(DataSource dataSource) {
		this.dataSource = dataSource;
	}
	public DataSourceTransactionManager getTran() {
		return tran;
	}
	public void setTran(DataSourceTransactionManager tran) {
		this.tran = tran;
	}
    public List chaxun(String sql) throws Exception {
        JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
        List resultList = jdbcTemplate.queryForList(sql);
        return resultList;
  }
    public int update(String sql) throws Exception {
        JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
        int resultList = jdbcTemplate.update(sql);
        return resultList;
  }
    
    public String getdatasourcename()throws Exception{
    	try{
    		JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    		Connection connection=jdbcTemplate.getDataSource().getConnection();
    		DatabaseMetaData md = connection.getMetaData();
    		connection.close();
    		return md.getDatabaseProductName();
    		
    	}catch(Exception e){
			throw e; 
    	}
    }
	public List QueryPersonUseExecute(String sql,int[] types,Object[] params)throws Exception{
		JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
		List result=null;
		log.debug("sql:"+sql);
		try{
			result=jdbcTemplate.queryForList(sql,params,types);
		}catch(Exception e){
			 log.error("出错SQL："+sql);
			 throw e;  
		}
		return result;
	}

}
